package com.hy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hy.dto.user.HeatMapData;
import com.hy.entity.UserAddress;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserAddressMapper extends BaseMapper<UserAddress> {
    /**
     * 按省份统计用户数量
     */
//    @Select("SELECT p.provinces_name AS name, p.center_longitude AS longitude, p.center_latitude AS latitude, COUNT(ua.id) AS count " +
//            "FROM user_address ua " +
//            "JOIN provinces p ON ua.provinces = p.id " +
//            "WHERE ua.delete_flag = 0 AND p.delete_flag = 0 " +
//            "GROUP BY ua.provinces")
    List<HeatMapData> countUsersByProvince();

    /**
     * 按城市统计用户数量
     */
//    @Select("SELECT c.cities_name AS name, c.center_longitude AS longitude, c.center_latitude AS latitude, COUNT(ua.id) AS count " +
//            "FROM user_address ua " +
//            "JOIN cities c ON ua.cities = c.id " +
//            "WHERE ua.delete_flag = 0 AND c.delete_flag = 0 " +
//            "GROUP BY ua.cities")
    List<HeatMapData> countUsersByCity();

    /**
     * 按区县统计用户数量
     */
//    @Select("SELECT d.districts_name AS name, d.center_longitude AS longitude, d.center_latitude AS latitude, COUNT(ua.id) AS count " +
//            "FROM user_address ua " +
//            "JOIN districts d ON ua.districts = d.id " +
//            "WHERE ua.delete_flag = 0 AND d.delete_flag = 0 " +
//            "GROUP BY ua.districts")
    List<HeatMapData> countUsersByDistrict();

    /**
     * 获取所有用户的经纬度坐标
     */
//    @Select("SELECT p.center_longitude AS longitude, p.center_latitude AS latitude, 1 AS count " +
//            "FROM user_address ua " +
//            "JOIN provinces p ON ua.provinces = p.id " +
//            "WHERE ua.delete_flag = 0")
    List<HeatMapData> getAllUserLocations();


    // 按省份统计用户分布
    @MapKey("regionId")
    List<Map<String, Object>> countUsersByProvince2();

    // 按城市统计用户分布（指定省份）
    @MapKey("provinceId")
    List<Map<String, Object>> countUsersByCity2(@Param("provinceId") Long provinceId);

    // 按区县统计用户分布（指定城市）
    @MapKey("cityId")
    List<Map<String, Object>> countUsersByDistrict2(@Param("cityId") Long cityId);

    // 获取省份下的所有用户
    List<String> listUsersByProvince(@Param("provinceId") Long provinceId);

    // 获取城市下的所有用户
    List<String> listUsersByCity(@Param("cityId") Long cityId);

    // 获取区县下的所有用户
    List<String> listUsersByDistrict(@Param("districtId") Long districtId);
}
